$(function () {
    var querystring = window.location.search;
    var zzjgid = parent.CurTreeNode.ID;
    var nodeidx = (querystring.match(/node=(\w+)/))[1];
    var INFO = window.NODE[nodeidx];
    var id = "";
    if (nodeidx == "zhtj") {
        id = (querystring.match(/xmid=(\w*)/))[1];
    }
    else {
        id = (querystring.match(/id=(\w*)/))[1];
    }
    var title = (id == "" ? "新增" : "编辑");
    $(".title_left").text(title + "----" + INFO.title);
    function closeMe() {
        window.parent.$('#topTabs').tabs('close', title);
    }
    function alertOk() {
        $.auto.alert("提示", "保存成功！");
    }
    function insertZZjgid(updata) {
        if (nodeidx == "zhtj" && title == "新增") {
            updata.push({ name: "ZZJGID", value: parent.CurTreeNode.ID });
        }
    }
    if (id != "") {
        $.ajax(INFO.querybyIDUrl, { type: 'POST', data: { id: id, tableName: INFO.view }, dataType: 'json' })
            .done(function (row) {
            var opt = { values: row,
                canceled: closeMe, saved: alertOk };
            $.extend(opt, INFO.formOpt);
            $("#editFrm").autoForm(opt);
        });
    }
    else {
        $("#editFrm").autoForm($.extend({ canceled: closeMe, saved: alertOk, beforeSave: insertZZjgid }, INFO.formOpt));
    }
});
